﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;
using System.Web.UI;
using System.Web.Util;
using System.Web;

namespace  FileOperationWinform
{
    public class FileLog
    {
        public static string GetMapPath(string strPath)
        {
            if (HttpContext.Current!=null)
            {
                return HttpContext.Current.Server.MapPath((strPath));
            }
            else
            {
                if (strPath.StartsWith("~/"))
                {
                    strPath = strPath.Substring(2);
                }else if (strPath.StartsWith("/"))
                {
                    strPath = strPath.Substring(1);
                }
                return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
            }
        }
        public static void writelog(string filename,string content)
        {
            string path=GetMapPath(filename);
            try
            {
                if (!File.Exists(path))
                {
                    StreamWriter sw=File.CreateText(path);
                    sw.WriteLine("----------Log Start---------"+DateTime.Now.ToString());
                    sw.Flush();
                    sw.Close();
                }

                StreamWriter sw2=File.AppendText(path);
                sw2.WriteLine("---"+DateTime.Now.ToString()+"----"+content);
                sw2.Flush();
                sw2.Close();
            }
            catch (System.Exception ex)
            {
            	
            }
        }
    }
}
